package me.jiatao.jetpack;

import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.util.List;

import me.jiatao.jetpack.databinding.User;
import me.jiatao.jetpack.viewmodel.MyViewModel;

public class ViewModelActivity extends AppCompatActivity {

    private static final String TAG = "***ViewModelActivity***";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_model);

        MyViewModel model = ViewModelProviders.of(this).get(MyViewModel.class);
        model.getUsers().observe(this, new Observer<List<User>>() {
            @Override
            public void onChanged(@Nullable List<User> users) {
                for (User user : users) {
                    Log.i(TAG, user.toString());
                }
            }
        });
    }
}
